﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LC;

namespace Scan
{
    public partial class UpdateArchivesView : BaseView
    {
        NLog.Logger logger = NLog.LogManager.GetLogger("[UpdateArchivesView]");

        #region Initi Form

        public UpdateArchivesView()
        {
            InitializeComponent();
            this.title = "档案更新菜单";
        }

        public override void OnLoad()
        {
            needClearView = true;
        }

        #endregion

        // 更新用户档案
        public override void NumPad1(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载用户档案...";
            this.TransferType = TransType.DownloadSysUser;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadSysUser();
            }
        }

        // 更新职员档案
        public override void NumPad2(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载职员档案...";
            this.TransferType = TransType.DownloadPersons;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadPersons();
            }
        }

        // 更新仓库档案
        public override void NumPad3(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载仓库档案...";
            this.TransferType = TransType.DownloadWarehouses;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadWarehouses();
            }
        }

        // 更新客商档案
        public override void NumPad4(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载客商档案...";
            this.TransferType = TransType.DownloadCompanys;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadCompanys();
            }
        }

        // 更新商品档案
        public override void NumPad5(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载商品档案...";
            this.TransferType = TransType.DownloadInventorys;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadInventorys();
            }
        }

        // 更新全部档案
        public override void NumPad6(object sender, EventArgs e)
        {
            this.TransferTitle = "正在下载全部档案...";
            this.TransferType = TransType.DownloadAllArchives;
            if (!Device.CheckNetworkStat())
            {
                this.OnConnectStart();
            }
            else
            {
                this.Enabled = false;
                this.ParentForm.ShowProgress(this.TransferTitle, false);
                GlobalCache.Instance.TransMgr.TransNotify += new TransactNotifyEventHandler(this.TransactNotify);
                GlobalCache.Instance.TransMgr.DownloadAllArchives();
            }
        }

        // 返回
        public override void Escape(object sender, EventArgs e)
        {
            this.ParentForm.LoadView(this.ResultView.GetType(), null, true, false);
        }
    }
}
